<!--=============================================
=            Footer         =
=============================================-->

<div class="footer-container pt-60 pb-60">
    <!--=======  footer navigation container  =======-->
    <!--=======  footer bottom navigation  =======-->
    <div class="footer-bottom-navigation text-center mb-20">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <!--=======  navigation-container  =======-->

                    <div class="navigation-container">
                        <ul>
                            <li><a href="#">Facebook</a> <span class="separator">|</span></li>
                            <li><a href="#">Facebook</a> <span class="separator">|</span></li>
                            <li><a href="#">Facebook</a> <span class="separator">|</span></li>
                            <li><a href="#">Facebook</a> <span class="separator">|</span></li>
                            <li><a href="#">Facebook</a></li>
                        </ul>
                    </div>

                    <!--=======  End of navigation-container  =======-->
                </div>
            </div>
        </div>
    </div>

    <!--=======  End of footer bottom navigation  =======-->

    <!--=======  copyright section  =======-->

    <div class="copyright-section text-center">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <!--=======  Copyright text  =======-->

                    <p class="copyright-text">Copyright @ 2021 Teaser. All Rights Reserved</p>

                    <!--=======  End of Copyright text  =======-->
                </div>
            </div>
        </div>
    </div>

    <!--=======  End of copyright section  =======-->
</div>

<!--=====  End of Footer  ======-->

<!-- scroll to top  -->
<a href="#" class="scroll-top"></a>
<!-- end of scroll to top -->

<!-- JS
============================================ -->


<!-- Popper JS -->
<script src="__HOME__js/popper.min.js"></script>

<!-- Bootstrap JS -->
<script src="__HOME__js/bootstrap.min.js"></script>

<!-- Plugins JS -->
<script src="__HOME__js/plugins.js"></script>

<!-- Main JS -->
<script src="__HOME__js/main.js"></script>
<script src="__PUBLIC__plugins/layer/layer.js"></script>

<script>
    //获取购物车
    function getCart() {
        $.ajax({
            type: "POST",
            url: "{:Url('home/cart/cart')}?do=get",
            timeout: "30000",
            dataType: "JSON",
            success: function (res) {
                data = res.data;
                if (res.code == 1) {
                    $("#x_count").text(data.count);
                    var html = '';
                    if (data.list.length > 0) {
                        $.each(data.list, function (i, item) {
                            html += '<div class="cart-float-single-item d-flex">\n' +
                                '       <span class="remove-item" data-id="' + item.id + '">' +
                                '           <a href="javascript:;"><i class="fa fa-times"></i></a>' +
                                '       </span>' +
                                '       <div class="cart-float-single-item-image">\n' +
                                '           <a href="{:url("home/product/show")}?id=' + item.product_id + '">' +
                                '           <img src="' + item.product_pic + '" class="img-fluid" alt=""></a>' +
                                '       </div>\n' +
                                '       <div class="cart-float-single-item-desc">\n' +
                                '           <p class="product-title1">' +
                                '           <a href="{:url("home/product/show")}?id=' + item.product_id + '">' + item.product_title +
                                '           </a></p>\n' +
                                '           <p class="price"><span class="quantity">' + item.num  + ' </span> ' +  ' ' + '</p>\n' +
                                '       </div>\n' +
                                '   </div>';
                        });
                    }
                    $("#cart-floating-box .cart-items").html(html);
                   // $("#total").text('$' + data.total);
                } else {
                    //alert('Network Failure, Please Refresh And Try Again');
                }
            },
            error: function () {
                //alert("Request Timeout, Please Refresh And Try Again");
            }
        });
    }

    //添加到购物车
    function addToCart(id,num) {
        var ind = layer.load(1, {
            shade: [0.1, '#000'] //0.1透明度的白色背景
            //,time: 4000 时间
        });
        var datas = {'id': id, 'num': num};
        $.ajax({
            type: "POST",
            url: "{:Url('home/cart/cart')}?do=add",
            data: datas,
            timeout: "4000",
            dataType: "JSON",
            success: function (res) {
                if (res.code == 1) {
                    layer.close(ind);
                    layer.msg('Added To Cart!');
                    getCart();
                } else {
                    layer.close(ind);
                    //layer.msg('Network Error, Please Refresh And Try Again');
                    layer.msg(res.msg);
                }
            },
            error: function () {
                layer.close(ind);
                layer.msg("Request Timeout, Please Refresh And Try Again");
            }
        });
    }

    getCart();

    //移除
    $(document).on('click', '.remove-item', function () {
        var id = $(this).attr('data-id');
        var tp = $(this).attr('data-tp');
        var that = $(this);
        $.ajax({
            type: "GET",
            url: "{:Url('home/cart/cart')}?do=del&id=" + id,
            timeout: "30000",
            dataType: "JSON",
            success: function (data) {
                if (data.code === 1) {
                    getCart();
                    if(tp == 2){
                        that.parent().parent().find('.x-'+id).remove();
                    }
                } else {
                    alert('Network Failure, Please Refresh And Try Again');
                }
            },
            error: function () {
                alert("Request Timeout, Please Refresh And Try Again");
            }
        });
    })

    //列表+
    $(".inc").click(function () {
        var num = $(this).parent('.pro-qty').find('input').val();
        console.log(num);
        var id = $(this).parent('.pro-qty').attr('data-id');
        var datas = {'id': id, 'zt': num};
        var _that = $(this);
        $.ajax({
            type: "POST",
            url: "{:Url('home/cart/cart')}?do=update",
            data: datas,
            timeout: "30000",
            dataType: "JSON",
            success: function (res) {
                data = res.data;
                if (res.code == 1) {
                    _that.parent().parent().parent().find('.pro-subtotal').html("<span>$"+data.subtotal+"</span>");
                    $('.x_total').text('$'+data.total);
                    getCart();
                } else {
                    alert('Network Failure, Please Refresh And Try Again');
                }
            },
            error: function () {
                alert("Request Timeout, Please Refresh And Try Again");
            }
        });
    })
    //列表-
    $(".dec").click(function () {
        var num = $(this).parent('.pro-qty').find('input').val();
        console.log(num);
       // var num = parseInt(n) - 1;
        if (num == 0) {
            console.log(666);
            $(this).parent('.pro-qty').find('input').val(1)
            return;
        }
        var id = $(this).parent('.pro-qty').attr('data-id');
        var datas = {'id': id, 'zt': num};
        var _that = $(this);
        $.ajax({
            type: "POST",
            url: "{:Url('home/cart/cart')}?do=update",
            data: datas,
            timeout: "30000",
            dataType: "JSON",
            success: function (res) {
                data = res.data;
                if (res.code == 1) {
                    _that.parent().parent().parent().find('.pro-subtotal').html("<span>$"+data.subtotal+"</span>");
                    $('.x_total').text('$'+data.total);
                    getCart();
                } else {
                    alert('Network Failure, Please Refresh And Try Again');
                }
            },
            error: function () {
                alert("Request Timeout, Please Refresh And Try Again");
            }
        });
        $(this).next().text(num);
    });

</script>

</body>

</html>
